<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册-TPshop开源商城</title>
    <link rel="stylesheet" href="./css/register-1.css">
</head>

<body>
    <header>
        <!-- log_1 链接 -->
        <a href="http://localhost:3000">
            <img src="./img/pc_home_logo_default.png">
        </a>
        <span>欢迎注册</span>
    </header>
    <section>
        <div class="phone">
            <span><a href="./register_1.html" class="SJ">手机注册</a> </span>
            <span><a href="./register_2.html" class="YX">邮箱注册</a></span>
            <!-- log_1 链接 -->
            <span>我已注册，马上<a href="./land.html">登录></a></span>
        </div>
        <div class="reg">
            <P class="reg_1"><span>手机号码：</span> <input type="text" class="reg_sj" id="phone" value="" placeholder="请输入手机号码"
                    autocomplete="off"></P>
            <P class="reg_2">
                <span>图像验证码：</span>
                <input type="text" class="reg_yz" placeholder="图像验证码">
                <i>未写</i>
                <a class="shuaX"><img onclick="" src="./img/chg_image.png" class=""></a>

            </P>
            <P class="reg_3"><span>设置密码：</span><input type="password" class="reg_mm" id="setpassword" placeholder="6-16位大小写英文字母、数字或符号的组合"
                    autocomplete="off"></P>
            <P class="reg_3"><span> 确认密码：</span><input type="password" class="reg_qr" id="setpassword" placeholder="请再次输入密码"
                    autocomplete="off"></P>
            <P class="reg_3"><span></span>我已阅读并同意<a href="http://demo6.tp-shop.cn/Home/Article/agreement/doc_code/agreement.html">《服务协议》</a></P>
            <div class="reg_4">
                <button type="submit"  id="register">同意协议并注册</button>
            </div>

        </div>

    </section>
</body>
<script src="./libs/jquery.js"></script>
<script>
      // 点击注册按钮，开始注册功能
      $("#register").click(function(){
          // console.log($("#phone").val());
          // console.log($("#setpassword").val());
        $.ajax({
            url:"http://localhost:3000/api",
            data:{
                 type:"register",
                 username: $("#phone").val(),
                 password: $("#setpassword").val()
            },
            success:res=>{
                // console.log(res);
				res = JSON.parse(res);
				if(res.code === 3){
				    // 成功后的交互
				    if(confirm("注册成功，是否跳转到登录")){
				        // 跳转到登录
						location.assign("http://localhost:3000/land.html")
				    }
				}else{
				    // 失败后的交互
				    alert("注册失败，" + res.title);
				    $("#phone").val("");
					$("#setpassword").val("")
				    $("#phone")[0].focus();
				}
            }
        })

          return false;
      })
  
</script>

</html>